<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Search extends CI_Controller {

	public function index()
	{
           date_default_timezone_set('America/New_York'); 
           $want=$this -> input -> post("want",TRUE);
           $teach=$this-> input -> post("teach",TRUE);
           $this->load->model('skills');
           // now get trade/master list
           $this->load->model('trade');
           $this->trade->initialise($this->skills->getTeachId($teach),$this->skills->getLearnId($want));
           $trades = $this->trade->getTrades();
           $tradesList = array();
           foreach($trades->result() as $trade){
               $expireDate = $trade->EXPIRATION_DT;
               $phpdate = strtotime( $expireDate );
               $mysqldate = date( 'm/d/Y', $phpdate );
               $tradeDesc = $trade->DESCRIPTION;
               $skillName=$trade->SKILL_NAME;
               $skillDesc=$trade->SKILL_DESCRIPTION;
               $skillType=$trade->SKILL_TYPE;
               $lastName=$trade->LAST_NAME;
               $firstName=$trade->FST_NAME;
               $toTeachId=$trade->TO_TEACH_SKILL_ID;
               $teachName=$this->skills->getNameById($toTeachId);
               $toLearnId = $trade->TO_LEARN_SKILL_ID;
               $learnName=$this->skills->getNameById($toLearnId);
               $uid=$trade->uid;
               $tradeSet = array(
                   'skillName'=>$skillName,
                   'skillDesc'=>$skillDesc,
                   'skillType'=>$skillType,
                   'tradeDesc'=>$tradeDesc,
                   'expireDate'=>$mysqldate,
                   'firstName'=>$firstName,
                   'lastName'=>$lastName,
                   'toTeachName'=>$teachName,
                   'toLearnName'=>$learnName,
                   'want'=>$want,
                   'uid'=>$uid,
                   'teach'=>$teach);
               array_push($tradesList, $tradeSet);// each trade result
           }
             $isLogin = $this->session->userdata('is_login');
            if(isset($isLogin)){
                $hasSession=$isLogin;
            }else{
                $hasSession=FALSE;
            }
            $data=array("hasSession"=>$hasSession,'trades'=>$tradesList);
           
           $this->load->view('searchpage',$data);
	}
}



